package com.gw.detail.controllor.detail;

import com.gw.detail.domain.PersonData;
import com.gw.detail.service.IPersonDataService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 人员数据Controller
 *
 * @author WangBin
 * @date 2021-04-30
 */
@RestController
@RequestMapping("/detail/persdat")
public class PersdatController extends BaseController {
    @Autowired
    private IPersonDataService persdatService;

    /**
     * 查询人员数据列表
     */
    @PreAuthorize("@ss.hasPermi('detail:persdat:list')")
    @GetMapping("/list")
    public TableDataInfo list(PersonData personData) {
        startPage();
        List<PersonData> list = persdatService.selectPersdatList(personData);
        return getDataTable(list);
    }

    /**
     * 导出人员数据列表
     */
    @PreAuthorize("@ss.hasPermi('detail:persdat:export')")
    @Log(title = "人员数据", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PersonData personData) {
        List<PersonData> list = persdatService.selectPersdatList(personData);
        ExcelUtil<PersonData> util = new ExcelUtil<PersonData>(PersonData.class);
        return util.exportExcel(list, "人员数据数据");
    }

    /**
     * 获取人员数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('detail:persdat:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(persdatService.selectPersdatById(id));
    }

    /**
     * 新增人员数据
     */
    @PreAuthorize("@ss.hasPermi('detail:persdat:add')")
    @Log(title = "人员数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PersonData personData) {
        return toAjax(persdatService.insertPersdat(personData));
    }

    /**
     * 修改人员数据
     */
    @PreAuthorize("@ss.hasPermi('detail:persdat:edit')")
    @Log(title = "人员数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PersonData personData) {
        return toAjax(persdatService.updatePersdat(personData));
    }

    /**
     * 删除人员数据
     */
    @PreAuthorize("@ss.hasPermi('detail:persdat:remove')")
    @Log(title = "人员数据", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(persdatService.deletePersdatByIds(ids));
    }
}
